﻿using ZYCommon;
using System;
using System.Xml;

namespace TextEditor
{
   

    public class ZYTextListItem
    {
        public bool Selected = false;
        public string Text = null;
        public string Value = null;

        public void CopyTo(ZYTextListItem myItem)
        {
            if (myItem != null)
            {
                myItem.Value = this.Value;
                myItem.Text = this.Text;
                myItem.Selected = this.Selected;
            }
        }

        public bool FromXML(XmlElement myElement)
        {
            if (myElement != null)
            {
                if (myElement.HasAttribute("value"))
                {
                    this.Value = myElement.GetAttribute("value");
                }
                else
                {
                    this.Value = myElement.InnerText;
                }
                this.Text = myElement.InnerText;
                this.Selected = myElement.HasAttribute("selected");
            }
            return true;
        }

        public static string GetXMLName()
        {
            return "option";
        }

        public override string ToString()
        {
            return this.Text;
        }

        public bool ToXML(XmlElement myElement)
        {
            if (myElement != null)
            {
                myElement.InnerText = this.Text;
                if (!StringCommon.isBlankString(this.Value) && (this.Value != this.Text))
                {
                    myElement.SetAttribute("value", this.Value);
                }
                if (this.Selected)
                {
                    myElement.SetAttribute("selected", "1");
                }
            }
            return true;
        }
    }
}

